package com.ztf0337.mycurriculumdesign.dao;

import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;

import com.ztf0337.mycurriculumdesign.entity.ParkingSpace;
import com.ztf0337.mycurriculumdesign.entity.RentedParkingSpace;

import java.util.List;

@Dao
public interface RentDao {

    @Insert
    long insert(RentedParkingSpace rentedParkingSpace);
    @Delete
    void delete(RentedParkingSpace rentedParkingSpace);
    @Update
    void update(RentedParkingSpace rentedParkingSpace);
    @Query("SELECT * FROM rent_table WHERE id = :id")
    RentedParkingSpace getRentById(Long id);

    @Query("SELECT * FROM rent_table WHERE user_id = :id")
    List<RentedParkingSpace> getRentsByUserId(Long id);

    @Query("SELECT * FROM rent_table WHERE parking_space_number LIKE '%' || :content || '%' " +
            "AND user_id = :user_id")
    List<RentedParkingSpace> searchRents(String content, Long user_id);

    @Query("DELETE FROM rent_table WHERE user_id = :id")
    void deleteRentsByUserId(Long id);

}
